<?php

namespace App\Providers;

use Laravel\Horizon\Horizon;
use Illuminate\Support\Facades\Gate;
use Laravel\Horizon\HorizonApplicationServiceProvider;

class HorizonServiceProvider extends HorizonApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Horizon::auth(function ($request) {

            if (app()->environment('dev', 'develop')) {
                return true;
            }

            if (in_array(ip(), [
                '45.117.97.64',
                '61.61.134.118',
                '127.0.0.1'
            ])) {
                return true;
            }

            return false;
        });
    }

    /**
     * Register the Horizon gate.
     *
     * This gate determines who can access Horizon in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {
        Gate::define('viewHorizon', function ($user) {
            return in_array(ip(), [
                '45.117.97.64',
                '61.61.134.118',
                '127.0.0.1'
            ]);
        });
    }
}
